package com.lwgk.mvp.view;

import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.lwgk.R;
import com.lwgk.adapter.HomePagerAdapter;
import com.lwgk.basic.BasicBelowActionBarActivity;
import com.lwgk.been.TabBean;
import com.lwgk.mvp.fragmentview.HomeFragment;
import com.lwgk.mvp.fragmentview.LectureFragment;
import com.lwgk.mvp.fragmentview.MineFragment;
import com.lwgk.mvp.fragmentview.RareBookFragment;
import com.lwgk.utils.DpChengeUtils;
import com.lwgk.widget.CustomizeTabLayout;
import com.lwgk.widget.NoScrollerViewPager;

import java.util.ArrayList;
import java.util.List;


/**
 * created by 赵航
 * 联系微信 微信号：zhao--hang--
 * on 2019/7/12
 * --------------------------------------------------------------------------
 * 描述：主界面
 * 注意事项：网络图片不能太大，部分手机可能会加载不出来
 */
public class HomeActivity extends BasicBelowActionBarActivity {

    private NoScrollerViewPager mHomeViewPager;
    private List<Fragment>      mFragments;
    private CustomizeTabLayout  mHomeTab;

    private String[]           mTitles   = {"刷题", "秘籍", "听课", "我的"};
    private ArrayList<TabBean> mTabbeans = new ArrayList<>();
    private String[] mSelectUrls={"http://pic38.nipic.com/20140307/2531170_074502124000_2.jpg",
            "http://pic72.nipic.com/file/20150719/9583477_022559838000_2.jpg",
            "http://img1.imgtn.bdimg.com/it/u=1283566983,3267885599&fm=21&gp=0.jpg",
            "http://pic38.nipic.com/20140307/2531170_074502124000_2.jpg"};
    private String[] mUnSelectUrls={"http://img.taopic.com/uploads/allimg/110419/2376-11041Z15S685.jpg",
            "http://pic.taopic.com/uploads/allimg/140627/240424-14062G2544388-lp.jpg",
            "http://pic42.nipic.com/20140628/19074191_112631798000_2.jpg",
            "http://pic74.nipic.com/file/20150807/21290976_162220169617_2.jpg"};

    private int mSelectColor = Color.BLUE;
    private int mUnSelectColor = Color.BLACK;
    private int[]           mUnSelectIcons = {
            R.drawable.miji, R.drawable.no_active,
            R.drawable.no_listener, R.drawable.no_my};
    private int[]           mSelectIcons   = {
            R.drawable.no_miji, R.drawable.active,
            R.drawable.listener, R.drawable.my};
    @Override
    protected int setContentSuccessView() {
        return R.layout.activity_home;
    }

    @Override
    protected void initView() {
        mHomeViewPager = (NoScrollerViewPager) findViewById(R.id.home_viewpager);
        mHomeTab = (CustomizeTabLayout) findViewById(R.id.home_tabLayout);
        for (int i = 0; i < mTitles.length; i++) {
            mTabbeans.add(new TabBean(mTitles[i], mSelectUrls[i],mUnSelectUrls[i], mSelectColor, mUnSelectColor,mSelectIcons[i], mUnSelectIcons[i]));
//            mTabbeans.add(new TabBean(mTitles[i], null,null, mSelectColor, mUnSelectColor,mSelectIcons[i], mUnSelectIcons[i]));
        }

        mFragments = new ArrayList<>();
        mFragments.add(new HomeFragment());
        mFragments.add(new RareBookFragment());
        mFragments.add(new LectureFragment());
        mFragments.add(new MineFragment());
        HomePagerAdapter homePagerAdapter = new HomePagerAdapter(getSupportFragmentManager(), mFragments);
        mHomeViewPager.setAdapter(homePagerAdapter);


        mHomeTab.setTabDate(mTabbeans);
        mHomeTab.setmListener(new CustomizeTabLayout.OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                mHomeViewPager.setCurrentItem(position, false);
            }
            /**
             * 连续点击调用此方法
             */
            @Override
            public void onTabReselect(int position) {

            }
        });
        mHomeViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                mHomeTab.setCurrentTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }


    @Override
    protected void initData() {

    }

}
